<template>
  <div class="page-container">
    <button class="back-button" @click="goToHome">
      <span class="icon-arrow-left"></span>
      返回首页
    </button>
    <h1>紧急调度</h1>
    <p>处理紧急工单，快速指派资源和人员进行响应</p>

    <!-- 紧急工单列表 -->
    <div class="order-list">
      <div class="order-card" v-for="order in emergencyOrders" :key="order.id">
        <div class="order-header">
          <span class="order-id">工单编号：{{ order.id }}</span>
          <span class="priority-tag" :class="order.priority">{{ order.priorityText }}</span>
        </div>
        <div class="order-content">
          <p><strong>事发地址：</strong>{{ order.address }}</p>
          <p><strong>事件描述：</strong>{{ order.description }}</p>
          <p><strong>上报时间：</strong>{{ order.reportTime }}</p>
          <p><strong>当前状态：</strong><span :class="`status ${order.status}`">{{ order.statusText }}</span></p>
        </div>
        <div class="order-actions">
          <button class="action-btn" @click="handleDispatch(order.id)" :disabled="order.status !== 'pending'">
            立即派单
          </button>
          <button class="action-btn secondary" @click="viewDetails(order.id)">
            查看详情
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'EmergencyDispatch',
  data() {
    return {
      emergencyOrders: [
        {
          id: 'EMG-2023-001',
          priority: 'critical',
          priorityText: '特级紧急',
          address: '东城区建国门街道88号',
          description: '设备突发故障，影响正常运营，需立即处理',
          reportTime: '2023-10-15 09:23',
          status: 'pending',
          statusText: '待处理'
        },
        {
          id: 'EMG-2023-002',
          priority: 'high',
          priorityText: '高度紧急',
          address: '西城区复兴门内大街15号',
          description: '网络中断，多个工作站无法连接',
          reportTime: '2023-10-15 10:05',
          status: 'processing',
          statusText: '处理中'
        }
      ]
    }
  },
  methods: {
    goToHome() {
      this.$router.push('/home');
    },
    handleDispatch(orderId) {
      // 处理派单逻辑
      this.$message.success(`紧急工单 ${orderId} 已派单成功`);
      const order = this.emergencyOrders.find(item => item.id === orderId);
      if (order) {
        order.status = 'processing';
        order.statusText = '处理中';
      }
    },
    viewDetails(orderId) {
      // 查看详情逻辑
      this.$router.push(`/emergency/detail/${orderId}`);
    }
  }
}
</script>

<style scoped>
.page-container {
  padding: 20px;
}

.order-list {
  margin-top: 20px;
  display: grid;
  gap: 15px;
}

.order-card {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  transition: all 0.3s;
}

.order-card:hover {
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #e0e0e0;
}

.order-id {
  font-weight: 600;
  color: #333;
}

.priority-tag {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: white;
}

.priority-tag.critical {
  background: #e74c3c;
}

.priority-tag.high {
  background: #f39c12;
}

.order-content {
  margin-bottom: 15px;
  line-height: 1.6;
}

.status {
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
}

.status.pending {
  background: #ecf0f1;
  color: #7f8c8d;
}

.status.processing {
  background: #3498db;
  color: white;
}

.order-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.action-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.action-btn:not(.secondary) {
  background: #e74c3c;
  color: white;
}

.action-btn:not(.secondary):hover {
  background: #c0392b;
}

.action-btn.secondary {
  background: #ecf0f1;
  color: #333;
}

.action-btn.secondary:hover {
  background: #dcdde1;
}

.action-btn:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
}

/* 复用基础样式 */
.back-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 15px;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s;
  margin-right: 20px;
  font-weight: 500;
}

.back-button:hover {
  background: #2980b9;
  transform: translateY(-2px);
}
</style>